'use strict';

const baseResultServer = require('./baseresult');
class goodsService extends baseResultServer {
  // 更新用户信息
  async findGoods(form) {
    const { ctx } = this;
    let result = '';
    let page = parseInt(form.page);
    let priceLevel =form.priceLevel;
    let pageSize = parseInt(form.pagesize);
    let sort = parseInt(form.sort);
    let skip = (parseInt(form.page))*parseInt(form.pagesize);
    var priceGt = '', //大于xxx区间
    priceLte = '';//小于xxx区间
    let params = {};
   if(priceLevel != 'all'){
     switch (priceLevel) {
       case '0':priceGt = 0;priceLte=100;break;
       case '1':priceGt = 100;priceLte=500;break;
       case '2':priceGt = 500;priceLte=1000;break;
       case '3':priceGt = 1000;priceLte=5000;break;
     }
     params = {
       salePrice:{
         $gt:priceGt,
         $lte:priceLte,
       }
     }
   }

    let goodsModel = await ctx.model.Goods.find(params).skip(skip).limit(pageSize).sort({'salePrice':sort}).then((doc)=> {
        result = this.successFun(doc)
      }).catch((err)=> {
        result = this.errorFun(err)
      });
    return result;
  }

}
module.exports = goodsService;
